﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Text.RegularExpressions;

namespace TimNilimaaConsulting.DeploymentWeb.Models
{
    public class Computer
    {
        public string Name { get; set; }
        public string MacAddress
        {
            get
            {
                return this.MacAddress;
            }
            set
            {
                if (value != String.Empty)
                {
                    Match success = Regex.Match(value, @"/^([0-9a-f]{1,2}[\.:-]){5}([0-9a-f]{1,2})$/i");
                    if (success.Success == false)
                    {
                        value = value.Trim(':', '-', '.');
                        success = Regex.Match(value, @"/^([0-9a-f]{1,2}[\.:-]){5}([0-9a-f]{1,2})$/i");
                        if (value.Length == 12)
                        {
                            var regex = "(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})";
                            var replace = "$1:$2:$3:$4:$5:$6";
                            value = Regex.Replace(value, regex, replace);   
                        }
                        if (value.Length == 12)
                        {
                            var regex = "(-{2})(-{2})(-{2})(-{2})(-{2})(-{2})";
                            var replace = "$1:$2:$3:$4:$5:$6";
                            value = Regex.Replace(value, regex, replace);
                        }
                    }
                }
                MacAddress = value;
            }
        }
        public UInt32 ResourceId { get; set; }
        public string OU { get; set; }
        public string Collection { get; set; }
        public string CollectionID { get; set; }
    }
}